package com.ruoyi.energy.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.energy.domain.DpEnergyQy;
import com.ruoyi.energy.service.IDpEnergyQyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 企业能源汇总Controller
 *
 * @author cjie
 * @date 2022-12-04
 */
@Api(tags = " 企业能源汇总")
@RestController
@RequestMapping("/dpEnergyQy")
public class DpEnergyQyController extends BaseController {
    @Autowired
    private IDpEnergyQyService dpEnergyQyService;

    /**
     * 查询企业能源汇总列表
     */
    @ApiOperation(value="查询企业能源汇总列表", notes="查询企业能源汇总列表")
    @PreAuthorize(hasPermi = "energy:dpEnergyQy:list")
    @GetMapping("/list")
    public TableDataInfo list(DpEnergyQy dpEnergyQy) {
        startPage();
        List<DpEnergyQy> list = dpEnergyQyService.selectDpEnergyQyList(dpEnergyQy);
        return getDataTable(list);
    }

    /**
     * 导出企业能源汇总列表
     */
    @ApiOperation(value="导出企业能源汇总列表", notes="导出企业能源汇总列表")
    @PreAuthorize(hasPermi = "energy:dpEnergyQy:export")
    @Log(title = "企业能源汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DpEnergyQy dpEnergyQy) throws IOException {
        List<DpEnergyQy> list = dpEnergyQyService.selectDpEnergyQyList(dpEnergyQy);
        ExcelUtil<DpEnergyQy> util = new ExcelUtil<DpEnergyQy>(DpEnergyQy.class);
        util.exportExcel(response, list, "企业能源汇总数据");
    }
    /**
     * 获取企业能源汇总详细信息
     */
    @ApiOperation(value="获取企业能源汇总详细信息", notes="获取企业能源汇总详细信息")
    @PreAuthorize(hasPermi = "energy:dpEnergyQy:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(dpEnergyQyService.selectDpEnergyQyById(id));
    }

    /**
     * 新增企业能源汇总
     */
    @ApiOperation(value="新增企业能源汇总", notes="新增企业能源汇总")
    @PreAuthorize(hasPermi = "energy:dpEnergyQy:add")
    @Log(title = "企业能源汇总", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DpEnergyQy dpEnergyQy) {
        return toAjax(dpEnergyQyService.insertDpEnergyQy(dpEnergyQy));
    }

    /**
     * 修改企业能源汇总
     */
    @ApiOperation(value="修改企业能源汇总", notes="修改企业能源汇总")
    @PreAuthorize(hasPermi = "energy:dpEnergyQy:edit")
    @Log(title = "企业能源汇总", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DpEnergyQy dpEnergyQy) {
        return toAjax(dpEnergyQyService.updateDpEnergyQy(dpEnergyQy));
    }

    /**
     * 删除企业能源汇总
     */
    @ApiOperation(value="删除企业能源汇总", notes="删除企业能源汇总")
    @ApiImplicitParam(name = "ids", value = "企业能源汇总ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "energy:dpEnergyQy:remove")
    @Log(title = "企业能源汇总", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(dpEnergyQyService.deleteDpEnergyQyByIds(ids));
    }
}
